package com.wechatapp.mengyao.poetry.biz;

import com.wechatapp.mengyao.poetry.core.CommonConstants;
import com.wechatapp.mengyao.poetry.vo.ChinesePoetryView;
import com.wechatapp.mengyao.poetry.entity.Favorite;
import com.wechatapp.mengyao.poetry.service.ChinesePoetryService;
import com.wechatapp.mengyao.poetry.service.FavoriteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yanghuaxu
 * @date 2025/5/21 17:16
 */
@Service
@Slf4j
public class PoetryBiz {

    @Autowired
    private ChinesePoetryService chinesePoetryService;
    @Autowired
    private FavoriteService favoriteService;

    public ChinesePoetryView getPoetryDetail(Integer poetryId) {
        ChinesePoetryView p = chinesePoetryService.getById(poetryId);
        Favorite favoritePoetry = favoriteService.getCurrentUserFavoritePoetry(poetryId);
        if (favoritePoetry != null) {
            p.setIsFavorite(CommonConstants.BOOLEAN_TRUE);
        } else {
            p.setIsFavorite(CommonConstants.BOOLEAN_FALSE);
        }
        return p;
    }

}
